﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using EHR.Common;
using System.IO;
using CommunitySystem.PageView.晋升管理;
using CommunitySystem.PageView;
using CommunitySystem.JinShengService;

namespace CommunitySystem
{
    public partial class PromotWindow : ChildWindow
    {
        private readonly JinShengService.JinShengServiceClient _client = new JinShengServiceClient();
        private int _id;
       public JinShengService.JinShen_MainInfo entity = null;
        private List<byte> fileContent = new List<byte>();
        private string _button = "";
        private PublicOfficialSelectionService.PublicOfficialSelectionServiceClient downLoadClient = null;
        public bool ReturnTrue = false;
        public bool Isnew = false;
        public PromotWindow(int id, string button)
        {
            InitializeComponent();
          
            downLoadClient = new PublicOfficialSelectionService.PublicOfficialSelectionServiceClient();
            downLoadClient.DownLoadFileCompleted += (sender, e) =>
            {
                var down = e.Result;
                fileContent.AddRange(down.Content);
                if (down.HasFinished == true)
                {
                    var stream = e.UserState as Stream;
                    stream.Write(fileContent.ToArray(), 0, fileContent.Count);
                    stream.Dispose();
                    stream.Close();
                    SilverlightMessageBoxLibrary.Message.InfoMessage("下载完毕!");
                }
                else
                {
                    down.StartPosition += down.Lenght;
                    downLoadClient.DownLoadFileAsync(down, e.UserState);
                }
            };

            dtbOrg.Parameter = new string[1] { "loginname=" + Session.LoginUser.LoginName };
            dtbOrg.Field = "OrgName";
            _client = new JinShengService.JinShengServiceClient();
            _id = id;
            _button = button;
            _client.GetJinShen_MainInfoCompleted += (sender, e) =>
            {
                entity = e.Result.FirstOrDefault();
                DataBinding();
            };
            dcbPromotionType.SelectionChanged += (sender, e) =>
            {
                if ((sender as ComboBox).SelectedValue != null)
                {
                    entity.PromotType = (sender as ComboBox).SelectedValue.ToString();
                    //if (!string.IsNullOrEmpty(entity.PromotType) && entity.PromotType.Equals("竞争上岗"))
                    //{
                    //    hlb.Visibility = System.Windows.Visibility.Visible;
                    //    wp.Visibility = System.Windows.Visibility.Visible;
                    //}
                    //else
                    //{
                    //    hlb.Visibility = System.Windows.Visibility.Collapsed;
                    //    wp.Visibility = System.Windows.Visibility.Collapsed;
                    //}
                }
            };
            ///保存
            _client.SaveJinShenMainInfoCompleted += (sender, e) =>
            {
                if (e.Error == null)
                {
                    SilverlightMessageBoxLibrary.Message.InfoMessage("保存成功");
                    ReturnTrue = true;
                    this.DialogResult = true;
                }
                else
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("保存失败，可能原因:\n" + e.Error.Message);
                    ReturnTrue = false;
                }
            };
            this.Loaded += new RoutedEventHandler(PromotWindow_Loaded);
        }


       

        public PromotWindow(int id, string button,bool isnew)
        {
            InitializeComponent();
            Isnew = isnew;
            downLoadClient = new PublicOfficialSelectionService.PublicOfficialSelectionServiceClient();
            downLoadClient.DownLoadFileCompleted += (sender, e) =>
            {
                var down = e.Result;
                fileContent.AddRange(down.Content);
                if (down.HasFinished == true)
                {
                    var stream = e.UserState as Stream;
                    stream.Write(fileContent.ToArray(), 0, fileContent.Count);
                    stream.Dispose();
                    stream.Close();
                    SilverlightMessageBoxLibrary.Message.InfoMessage("下载完毕!");
                }
                else
                {
                    down.StartPosition += down.Lenght;
                    downLoadClient.DownLoadFileAsync(down, e.UserState);
                }
            };

            dtbOrg.Parameter = new string[1] { "loginname=" + Session.LoginUser.LoginName };
            dtbOrg.Field = "OrgName";
            _client = new JinShengService.JinShengServiceClient();
            _id = id;
            _button = button;
            _client.GetJinShen_MainInfoCompleted += (sender, e) =>
            {
                entity = e.Result.FirstOrDefault();
                DataBinding();
            };
            dcbPromotionType.SelectionChanged += (sender, e) =>
            {
                if ((sender as ComboBox).SelectedValue != null)
                {
                    entity.PromotType = (sender as ComboBox).SelectedValue.ToString();
                    //if (!string.IsNullOrEmpty(entity.PromotType) && entity.PromotType.Equals("竞争上岗"))
                    //{
                    //    hlb.Visibility = System.Windows.Visibility.Visible;
                    //    wp.Visibility = System.Windows.Visibility.Visible;
                    //}
                    //else
                    //{
                    //    hlb.Visibility = System.Windows.Visibility.Collapsed;
                    //    wp.Visibility = System.Windows.Visibility.Collapsed;
                    //}
                }
            };
            ///保存
            _client.SaveJinShenMainInfoCompleted += (sender, e) =>
            {
                if (e.Error == null)
                {
                    SilverlightMessageBoxLibrary.Message.InfoMessage("保存成功");
                    ReturnTrue = true;
                    this.DialogResult = true;
                }
                else
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("保存失败，可能原因:\n" + e.Error.Message);
                    ReturnTrue = false;
                }
            };
            this.Loaded += new RoutedEventHandler(PromotWindow_Loaded);
        }
        private bool isadmin = false;
        public PromotWindow(JinShen_MainInfo item, string button, bool isnew, bool _isck)
        {
            InitializeComponent();
            Isnew = isnew;
            if (_isck)
            {
                OKButton.Visibility = Visibility.Collapsed;
                btnAdd.Visibility = Visibility.Collapsed;
            }
            _client.GetOrgForHRAsync(Session.LoginUser.LoginName);
            _client.GetOrgForHRCompleted += (sender, e) =>
            {
                if (JinShenConst.Administrator.Contains(e.Result))
                    isadmin = true;
                if (JinShenConst.HR.Contains(e.Result))
                    isadmin = false;
            };

            downLoadClient = new PublicOfficialSelectionService.PublicOfficialSelectionServiceClient();
            downLoadClient.DownLoadFileCompleted += (sender, e) =>
            {
                var down = e.Result;
                fileContent.AddRange(down.Content);
                if (down.HasFinished == true)
                {
                    var stream = e.UserState as Stream;
                    stream.Write(fileContent.ToArray(), 0, fileContent.Count);
                    stream.Dispose();
                    stream.Close();
                    SilverlightMessageBoxLibrary.Message.InfoMessage("下载完毕!");
                }
                else
                {
                    down.StartPosition += down.Lenght;
                    downLoadClient.DownLoadFileAsync(down, e.UserState);
                }
            };

            dtbOrg.Parameter = new string[1] { "loginname=" + Session.LoginUser.LoginName };
            dtbOrg.Field = "OrgName";
            _client = new JinShengService.JinShengServiceClient();
            _id = item.ID;
            _button = button;
            //_client.GetJinShen_MainInfoCompleted += (sender, e) =>
            //{
            //    entity = e.Result.FirstOrDefault();
            entity = item;
            DataBinding();
            //};
          
            dcbPromotionType.SelectionChanged += (sender, e) =>
            {
                if ((sender as ComboBox).SelectedValue != null)
                {
                    entity.PromotType = (sender as ComboBox).SelectedValue.ToString();
                    //if (!string.IsNullOrEmpty(entity.PromotType) && entity.PromotType.Equals("竞争上岗"))
                    //{
                    //    hlb.Visibility = System.Windows.Visibility.Visible;
                    //    wp.Visibility = System.Windows.Visibility.Visible;
                    //}
                    //else
                    //{
                    //    hlb.Visibility = System.Windows.Visibility.Collapsed;
                    //    wp.Visibility = System.Windows.Visibility.Collapsed;
                    //}
                }
            };
            //保存审核相关记录
            _client.AddJinShen_SHJLDetailCompleted += (ss, ee) =>
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("保存成功");
                ReturnTrue = true;
                this.DialogResult = true;
            };
            ///保存
            _client.SaveJinShenMainInfoCompleted += (sender, e) =>
            {
                if (e.Error == null)
                {
                    //SilverlightMessageBoxLibrary.Message.InfoMessage("保存成功");
                    //ReturnTrue = true;
                    //this.DialogResult = true;
                    JinShen_SHJLDetail shjl = new JinShen_SHJLDetail();
                     shjl.Name = "人员审核";
                    if (!string.IsNullOrEmpty(shjl.Name))
                        _client.AddJinShen_SHJLDetailAsync(shjl, null);
                }
                else
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("保存失败，可能原因:\n" + e.Error.Message);
                    ReturnTrue = false;
                }
            };
            this.Loaded += new RoutedEventHandler(PromotWindow_Loaded);
        }
        private PublicOfficialSelectionService.PublicOfficialSelectionServiceClient _uploadClient = null;
        void PromotWindow_Loaded(object sender, RoutedEventArgs e)
        {
            _uploadClient = new PublicOfficialSelectionService.PublicOfficialSelectionServiceClient();
            if (_id > 0)
            {
                this.Title = "编辑晋升信息";
                _client.GetJinShen_MainInfoAsync("ID = " + _id, EHR.Common.Session.LoginUser.LoginName);
               
            }
            else
            {
                this.Title = "新增晋升信息";
                entity = new JinShengService.JinShen_MainInfo() { Status = CommunitySystem.PageView.JinShenConst.STATUS_Solution_Submit, CreateUser = Session.LoginUser.LoginName };
                DataBinding();
            }
        }

        private void DataBinding()
        {
            this.DataContext = entity;
            dcbPromotionType.SelectedValue = entity.PromotType;
            #region 附件

            //if (entity.ID > 0 && entity.PromotType.Equals("竞争上岗") && entity.Attachment != null && entity.Attachment.Count > 0)
            if (entity.ID > 0 && entity.Attachment != null && entity.Attachment.Count > 0)
            {
                foreach (var attach in entity.Attachment)
                {
                    StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal, };
                    if (_button == "新增候选人")
                    {
                        HyperlinkButton hlb = new HyperlinkButton() { Content = attach.realname };
                        hlb.Click += (sender1, e1) =>
                        {
                            string extend = attach.realname.Split('.').LastOrDefault();
                            var openFile = new SaveFileDialog() { Filter = string.Format("{0}|*.{0}", extend) };
                            if (openFile.ShowDialog() == true)
                            {
                                fileContent.Clear();
                                downLoadClient.DownLoadFileAsync(new PublicOfficialSelectionService.DownLoadFile() { PathKey = "file", HasFinished = false, Lenght = 1600, FileName = attach.filename, StartPosition = 0 }, openFile.OpenFile());
                            }
                        };
                        sp.Children.Add(hlb);
                    }
                    else
                    {
                        sp.Children.Add(new TextBlock() { Text = attach.realname });
                        Image img = new Image() { Cursor = Cursors.Hand, Height = 15, Width = 15, };
                        img.Source = new System.Windows.Media.Imaging.BitmapImage(
                            new Uri("/CommunitySystem;component/Images/ViewDesign/delete.png",
                                UriKind.RelativeOrAbsolute));
                        sp.Children.Add(img);
                        img.MouseLeftButtonDown += (sender1, e1) =>
                        {
                            wp.Children.Remove(sp);
                            entity.Attachment.Remove(attach);
                        };
                    }
                    wp.Children.Add(sp);
                }
            }
            //if (!string.IsNullOrEmpty(entity.PromotType) && entity.PromotType.Equals("竞争上岗"))
            //{
            //    hlb.Visibility = System.Windows.Visibility.Visible;
            //    wp.Visibility = System.Windows.Visibility.Visible;
            //}
            //else
            //{
            //    hlb.Visibility = System.Windows.Visibility.Collapsed;
            //    wp.Visibility = System.Windows.Visibility.Collapsed;
            //}
            #endregion

           
            switch (_button)
            {
                case JinShenConst.ACTION_Solution_Modify:
                    if (entity.Status == CommunitySystem.PageView.JinShenConst.STATUS_SolutionPass || entity.Status == CommunitySystem.PageView.JinShenConst.STATUS_CandidateChecking)
                    {
                        this.OKButton.IsEnabled = false;
                    }
                    else if (entity.Status == CommunitySystem.PageView.JinShenConst.STATUS_Solution_Submit || entity.Status == CommunitySystem.PageView.JinShenConst.STATUS_Solution_Retire)
                    {
                        LayoutRoot.RowDefinitions[6].Height = new GridLength(0);
                        LayoutRoot.RowDefinitions[7].Height = new GridLength(0);
                        LayoutRoot.RowDefinitions[8].Height = new GridLength(0);
                        cadinator.Visibility = System.Windows.Visibility.Collapsed;
                        lbDetail.Visibility = System.Windows.Visibility.Collapsed;
                        btnAdd.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    break;
                
                case "新增候选人":
                    tbDepart.IsEnabled = false;
                    dtbPosition.IsEnabled = false;
                    dtbEducation.IsEnabled = false;
                    dtbOrg.IsEnabled = false;
                    dtbPolitical.IsEnabled = false;
                    dtbPositionAttr.IsEnabled = false;
                    dtbPositionLevel.IsEnabled = false;
                    dcbPromotionType.IsEnabled = false;
                    tbFenguan.IsEnabled = false;
                    hlb.Visibility = System.Windows.Visibility.Collapsed;
                    break;
              
                case JinShenConst.ACTION_Solution_New:
                default:
                        LayoutRoot.RowDefinitions[6].Height = new GridLength(0);
                        LayoutRoot.RowDefinitions[7].Height = new GridLength(0);
                        LayoutRoot.RowDefinitions[8].Height = new GridLength(0);
                        cadinator.Visibility = System.Windows.Visibility.Collapsed;
                        lbDetail.Visibility = System.Windows.Visibility.Collapsed;
                        btnAdd.Visibility = System.Windows.Visibility.Collapsed;
                    break;
            }
            if (entity.Details == null)
                entity.Details = new System.Collections.ObjectModel.ObservableCollection<JinShengService.JinShen_DetailInfo>();
            lbDetail.ItemsSource = entity.Details;
          

        }

       

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (!Isnew)
            {
                if (Validate())
                {
                    switch (_button)
                    {
                        case "新增候选人":
                            entity.Status = CommunitySystem.PageView.JinShenConst.STATUS_CandidateChecking;//"候选人审核";
                            break;
                        default:
                            entity.Status = CommunitySystem.PageView.JinShenConst.STATUS_Solution_Submit;
                            break;
                    }
                    if (entity.PromotType.Equals("竞争上岗") && files.Count > 0)
                    {
                        #region 上传文件
                        _uploadClient.UploadFileCompleted -= new EventHandler<PublicOfficialSelectionService.UploadFileCompletedEventArgs>(_uploadClient_UploadFileCompleted);
                        _uploadClient.UploadFileCompleted += new EventHandler<PublicOfficialSelectionService.UploadFileCompletedEventArgs>(_uploadClient_UploadFileCompleted);


                        foreach (var key in files.Keys)
                        {
                            var file = files[key];
                            _uploadClient.UploadFileAsync(fileDictionary, file.DisplayName, file.Context[0], true, file);
                            file.Context.RemoveAt(0);

                        }
                        #endregion
                    }
                    else
                    {
                        _client.SaveJinShenMainInfoAsync(entity);
                    }

                }
            }
            else
            {
                if (_button.Equals("新增候选人") && (entity.Status == JinShenConst.STATUS_CandidateChecking || entity.Status == JinShenConst.STATUS_CandidateCheck_UnPass))
                {
                    if (entity.Details == null || entity.Details.Count < 1)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("至少有一个位候选人!");
                        return ;
                    }
                }
                if (!isadmin && entity.PromotType == "竞争上岗" && _button.Equals("新增候选人") && (entity.Status == JinShenConst.STATUS_SolutionPass || entity.Status == JinShenConst.STATUS_CandidateChecking || entity.Status == JinShenConst.STATUS_CandidateCheck_UnPass))
                {
                    if (entity.Details == null || entity.Details.Count <= 1)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("竞争上岗候选人必须多于一个！");
                        return;
                    }
                }
                entity.Status = CommunitySystem.PageView.JinShenConst.STATUS_CandidateChecking;//"候选人审核";
                _client.SaveJinShenMainInfoAsync(entity);
                Isnew = false;
            }
        }

        void _uploadClient_UploadFileCompleted(object sender, PublicOfficialSelectionService.UploadFileCompletedEventArgs e)
        {
            var file = e.UserState as UploadFileInfo;
            if (file.Context.Count > 0)
            {
                _uploadClient.UploadFileAsync(fileDictionary, file.DisplayName, file.Context[0], false, file);
                file.Context.RemoveAt(0);
            }
            else
            {
                if (files.Values.LastOrDefault() == file)
                {
                    _client.SaveJinShenMainInfoAsync(entity);
                }
            }
        }

        private bool Validate()
        {
            if (string.IsNullOrEmpty(entity.Department))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("科室不能为空!");
                return false;
            }
            if (string.IsNullOrEmpty(entity.OrgName))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("单位不能为空!");
                return false;
            }
            if (string.IsNullOrEmpty(entity.Position))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("职位不能为空!");
                return false;
            }
            if (string.IsNullOrEmpty(entity.PositionAttibute))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("职务属性不能为空!");
                return false;
            }
            if (string.IsNullOrEmpty(entity.PositionLevel))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("职务属性不能为空!");
                return false;
            }
            if (string.IsNullOrEmpty(entity.Education))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("文化程度不能为空!");
                return false;
            }
            if (string.IsNullOrEmpty(entity.Political))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("政治面貌不能为空!");
                return false;
            }
            if (string.IsNullOrEmpty(entity.PromotType))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("晋升方式不能为空");
                return false;
            }

            if (entity.PromotType == "竞争上岗" && (entity.Attachment == null || entity.Attachment.Count < 1))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("竞争上岗必须上传方案附件!");
                return false;
            }

            if (entity.PromotType == "竞争上岗" && _button.Equals("新增候选人") && (entity.Status == JinShenConst.STATUS_SolutionPass || entity.Status == JinShenConst.STATUS_CandidateChecking || entity.Status == JinShenConst.STATUS_CandidateCheck_UnPass))
            {
                if (entity.Details == null || entity.Details.Count <= 1)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("竞争上岗候选人必须多于一个！");
                    return false;
                }
            }
            else  if (_button.Equals("新增候选人") && (entity.Status == JinShenConst.STATUS_CandidateChecking || entity.Status == JinShenConst.STATUS_CandidateCheck_UnPass))
            {
                if (entity.Details == null || entity.Details.Count < 1)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("至少有一个位候选人!");
                    return false;
                }
            }
            //if (string.IsNullOrEmpty(entity.Department))
            //{
            //    SilverlightMessageBoxLibrary.Message.ErrorMessage("");
            //    return false;
            //}
            return true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
        private readonly string fileDictionary = "file";
        private Dictionary<string, UploadFileInfo> files = new Dictionary<string, UploadFileInfo>();

        /// <summary>
        /// 上报方案
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            var openFile = new OpenFileDialog() { Multiselect = false };
            if (openFile.ShowDialog() == true)
            {
                string GuidName = Guid.NewGuid().ToString("N");
               // files.Add(GuidName, openFile.File.OpenRead());
                UploadFileInfo uploadFile = new UploadFileInfo() { DisplayName = GuidName, Name = GuidName };
                var stream = openFile.File.OpenRead();
                uploadFile.Size = stream.Length / 16000;
                uploadFile.Context = new List<byte[]>();
                int b = 0;

                while (stream.Position > -1 && stream.Position < stream.Length)
                {
                    if (stream.Length - stream.Position >= 16000)
                    {
                        b = 16000;
                    }
                    else
                    {
                        b = (int)(stream.Length - stream.Position);
                    }

                    byte[] filebyte = new byte[b];
                    stream.Read(filebyte, 0, b);
                    uploadFile.Context.Add(filebyte);
                }
                stream.Close();
                files.Add(GuidName, uploadFile);
                StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal,  };
                sp.Children.Add(new TextBlock() { Text = openFile.File.Name, });
                Image img = new Image() { Cursor = Cursors.Hand, Height = 15, Width = 15, Margin = new Thickness(5, 0, 0, 0) };
                img.Source = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("/CommunitySystem;component/Images/ViewDesign/delete.png",
                        UriKind.RelativeOrAbsolute));
                sp.Children.Add(img);
                if (entity.Attachment == null)
                    entity.Attachment = new System.Collections.ObjectModel.ObservableCollection<JinShengService.JinShen_MainInfo_Attatchment>();
                var att = new JinShengService.JinShen_MainInfo_Attatchment() { realname = openFile.File.Name, filename = GuidName, Key = fileDictionary };
                entity.Attachment.Add(att);
                img.MouseLeftButtonDown += (sender1, e1) =>
                {
                    wp.Children.Remove(sp);
                    files.Remove(GuidName);
                    entity.Attachment.Remove(att);
                   
                };
                wp.Children.Add(sp);
               
            }
        }

        /// <summary>
        /// 增加人
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (entity.OrgID != null)
            {
                AddEmpWindow wind = new AddEmpWindow((int)entity.OrgID, entity);
                wind.Show();
                wind.Closed += (sender1, e1) =>
                {
                    if (wind.DialogResult == true && wind.SelectItems != null)
                    {
                        if (entity.Details == null)
                            entity.Details = new System.Collections.ObjectModel.ObservableCollection<JinShengService.JinShen_DetailInfo>();
                        foreach (var emp in wind.SelectItems)
                        {
                            if (entity.Details.Where(c => c.EmpBasicID == emp.ID).Count() <= 0)
                            {
                                if (string.IsNullOrEmpty(emp.Gender))//破格
                                {
                                    entity.Details.Add(new JinShengService.JinShen_DetailInfo() { EmpBasicID = emp.ID, Name = emp.Name, IsPoGe = false });
                                }
                                else
                                {
                                    entity.Details.Add(new JinShengService.JinShen_DetailInfo() { EmpBasicID = emp.ID, Name = emp.Name, IsPoGe = true });
                                }
                            }
                            else
                            {
                                SilverlightMessageBoxLibrary.Message.InfoMessage(emp.Name + "已存在，不能重复添加");
                            }
                        }
                    }
                };
            }
            else
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("请选择单位");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dtbOrg_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals("SelectItem") && dtbOrg.SelectItem != null)
            {
                entity.OrgID = dtbOrg.SelectItem.Id;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var detail = (sender as Image).DataContext as CommunitySystem.JinShengService.JinShen_DetailInfo;
            if (detail != null)
            {
                entity.Details.Remove(detail);
            }
        }
    }
}

